package com.unidt.www.module.third.enterprise.controller.admin;

import com.unidt.www.framework.common.pojo.CommonResult;
import com.unidt.www.framework.common.pojo.PageResult;
import com.unidt.www.module.third.enterprise.domain.EnterpriseNoticeDO;
import com.unidt.www.module.third.enterprise.service.EnterpriseUserService;
import com.unidt.www.module.third.enterprise.vo.user.EnterpriseUserCreatReqVO;
import com.unidt.www.module.third.enterprise.vo.user.EnterpriseUserFollowReqVO;
import com.unidt.www.module.third.enterprise.vo.user.EnterpriseUserListReqVO;
import com.unidt.www.module.third.enterprise.vo.user.EnterpriseUserUpdateReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.unidt.www.framework.common.pojo.CommonResult.success;

/**
 * @author ouyangoyys
 * @since 2022-11-24
 */
@Api(tags = "企业码-我的关注")
@RestController
@RequestMapping("/enterprise-user-do")
@Validated
public class EnterpriseUserController {

    @Resource
    private EnterpriseUserService enterpriseUserService;



    @PostMapping("create")
    @ApiOperation("新增")
    public CommonResult<Long> create(@Valid @RequestBody EnterpriseUserCreatReqVO reqVO) {
        Long enterpriseId = enterpriseUserService.create(reqVO);
        return success(enterpriseId);
    }


    @PostMapping("follow")
    @ApiOperation("企业关注")
    public CommonResult<Long> follow(@Valid @RequestBody EnterpriseUserFollowReqVO reqVO) {
        Long enterpriseId = enterpriseUserService.follow(reqVO);
        return success(enterpriseId);
    }

    @PutMapping("update")
    @ApiOperation("更新关注")
    public CommonResult<Boolean> update(@Valid @RequestBody EnterpriseUserUpdateReqVO reqVO) {
        enterpriseUserService.update(reqVO);
        return success(true);
    }

    @DeleteMapping("delete")
    @ApiOperation("取消关注")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        enterpriseUserService.delete(id);
        return success(true);
    }

    @GetMapping("/list")
    @ApiOperation("获取关注列表")
    public CommonResult<PageResult<EnterpriseNoticeDO> > list(EnterpriseUserListReqVO reqVO) {

        PageResult<EnterpriseNoticeDO> list = enterpriseUserService.list(reqVO);

        return success(list);
    }
}
